package com.yn.admin.zy;

import com.yn.common.page.BasePage;
import com.yn.common.request.sc.PageParamRequest;
import com.yn.common.request.zy.DoctorAddRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.zy.TDoctorInfoService;
import com.yn.service.zy.model.dto.TDoctorInfoOutDTO;
import com.yn.service.zy.model.query.TDoctorInfoQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/admin/tdoctorinfo")
@Api(tags = "就医绿通")
@Slf4j
public class TDoctorInfoController {
    @Autowired
    private TDoctorInfoService tDoctorInfoService;


    /**
     * 新增专家
     * @param request 新增专家请求对象
     * @return
     */
    @ApiOperation("新增专家")
    @PostMapping("/save")
    public BaseResult<String> save(@RequestBody @Validated DoctorAddRequest request){
        log.info("新增专家入参:{}",request);
        tDoctorInfoService.saveDoctorInfo(request);
        return BaseResult.success("添加成功");
    }

    /**
     * 修改专家信息
     * @param request 修改专家信息请求对象
     * @return
     */
    @ApiOperation("修改专家信息")
    @PutMapping("/update")
    public BaseResult<String> update(@RequestBody @Validated DoctorAddRequest request){
        log.info("新增专家入参:{}",request);
        tDoctorInfoService.modifyDoctorInfo(request);
        return BaseResult.success("修改成功");
    }

    /**
     * 删除专家
     * @param doctorId 专家id
     * @return
     */
    @ApiOperation("删除专家信息")
    @DeleteMapping("/delete/{doctorId}")
    public BaseResult<String> update(@PathVariable @NotNull(message = "请选择专家") Integer doctorId){
        log.info("删除专家入参:{}",doctorId);
        tDoctorInfoService.deleteDoctorInfo(doctorId);
        return BaseResult.success("删除成功");
    }


    /**
     * 专家列表信息
     * @param query 查询条件
     * @param pageRequest 分页参数
     * @return
     */
    @ApiOperation("专家列表")
    @RequestMapping("/list-page")
    public BaseResult<BasePage<TDoctorInfoOutDTO>> listPage1(TDoctorInfoQuery query, PageParamRequest pageRequest){
        log.info("分页查询专家入参:{}",query);
        return BaseResult.success(tDoctorInfoService.listPageByQuery1(query,pageRequest));
    }

    /**
     * 详情数据
     */
    @ApiOperation("专家详情")
    @GetMapping("/get-info")
    public BaseResult<TDoctorInfoOutDTO> getInfo(@RequestParam(value = "doctorId",required = true)
                              @NotNull(message = "请选择专家")
                              @ApiParam(value = "专家id",required = true) Integer doctorId){
        TDoctorInfoOutDTO tDoctorInfoOutDTO = tDoctorInfoService.getInfo(doctorId);

        return BaseResult.success(tDoctorInfoOutDTO);
    }

}
